package com.gpjcjl.entity;

import java.io.Serializable;

/**
 * Created by hzy on 2019/1/23
 **/
public class Result<T> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseBean{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public boolean isSuccess() {
        return code == 1;
    }

    public static <T> Result<T> error() {
        return new Result<>(600, "服务异常");
    }

    public static <T> Result<T> success(String msg) {
        return new Result<>(1, msg);
    }

    public static <T> Result<T> success(String msg, T data) {
        Result<T> result = new Result<>(1, msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(600, msg);
    }

}
